/*
 * Copyright (c) 2009 John Pritchard, WTKX Project Group
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package wtkx.be;

import wtkx.Component;
import wtkx.ui.Mouse;
import wtkx.ui.Keyboard;

import jbxml.Resolver;

import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;

/**
 * Binding from the Component source to the application target for
 * WTKX event handlers.  Target methods are bound by name exclusively.
 * The target name must be unique in the target object class.
 * 
 * Method signatures are fixed by the caller.  The target method must
 * receive the caller's required parameters.
 * 
 * @author jdp
 */
public class Function
    extends jbxml.Function
{

    /**
     * Function classes defined for {@link wtkx.Component} generally
     * following the naming of HTML Intrinsic Events for their human
     * recall value.
     */
    public static class Type
        extends jbxml.Function.Type
    {
        public final static wtkx.be.Function.Type onload = new wtkx.be.Function.Type("onload",Boolean.TYPE,(new Class[]{Component.class}));
        public final static wtkx.be.Function.Type onunload = new wtkx.be.Function.Type("onunload",Boolean.TYPE,(new Class[]{Component.class}));
        public final static wtkx.be.Function.Type onclick = new wtkx.be.Function.Type("onclick",Boolean.TYPE,(new Class[]{Component.class,Mouse.Button.class,Float.TYPE,Float.TYPE}));
        public final static wtkx.be.Function.Type ondblclick = new wtkx.be.Function.Type("ondblclick",Boolean.TYPE,(new Class[]{Component.class,Mouse.Button.class,Float.TYPE,Float.TYPE}));
        public final static wtkx.be.Function.Type onmousedown = new wtkx.be.Function.Type("onmousedown",Boolean.TYPE,(new Class[]{Component.class,Mouse.Button.class,Float.TYPE,Float.TYPE}));
        public final static wtkx.be.Function.Type onmouseup = new wtkx.be.Function.Type("onmouseup",Boolean.TYPE,(new Class[]{Component.class,Mouse.Button.class,Float.TYPE,Float.TYPE}));
        public final static wtkx.be.Function.Type onmouseover = new wtkx.be.Function.Type("onmouseover",Boolean.TYPE,(new Class[]{Component.class}));
        public final static wtkx.be.Function.Type onmousemove = new wtkx.be.Function.Type("onmousemove",Boolean.TYPE,(new Class[]{Component.class,Float.TYPE,Float.TYPE}));
        public final static wtkx.be.Function.Type onmouseout = new wtkx.be.Function.Type("onmouseout",Boolean.TYPE,(new Class[]{Component.class}));
        public final static wtkx.be.Function.Type onmousewheel = new wtkx.be.Function.Type("onmousewheel",Boolean.TYPE,(new Class[]{Component.class,Mouse.ScrollType.class,Integer.TYPE,Integer.TYPE,Float.TYPE, Float.TYPE}));
        public final static wtkx.be.Function.Type onfocus = new wtkx.be.Function.Type("onfocus",Boolean.TYPE,(new Class[]{Component.class}));
        public final static wtkx.be.Function.Type onblur = new wtkx.be.Function.Type("onblur",Boolean.TYPE,(new Class[]{Component.class}));
        public final static wtkx.be.Function.Type onkeypress = new wtkx.be.Function.Type("onkeypress",Boolean.TYPE,(new Class[]{Component.class,Character.TYPE}));
        public final static wtkx.be.Function.Type onkeydown = new wtkx.be.Function.Type("onkeydown",Boolean.TYPE,(new Class[]{Component.class,Integer.TYPE,Keyboard.KeyLocation.class}));
        public final static wtkx.be.Function.Type onkeyup = new wtkx.be.Function.Type("onkeyup",Boolean.TYPE,(new Class[]{Component.class,Integer.TYPE,Keyboard.KeyLocation.class}));
        public final static wtkx.be.Function.Type onsubmit = new wtkx.be.Function.Type("onsubmit",Boolean.TYPE,(new Class[]{Component.class}));
        public final static wtkx.be.Function.Type onreset = new wtkx.be.Function.Type("onreset",Boolean.TYPE,(new Class[]{Component.class}));
        public final static wtkx.be.Function.Type onselect = new wtkx.be.Function.Type("onselect",Boolean.TYPE,(new Class[]{Component.class}));
        public final static wtkx.be.Function.Type onchange = new wtkx.be.Function.Type("onchange",Boolean.TYPE,(new Class[]{Component.class}));
        public final static wtkx.be.Function.Type reader = new wtkx.be.Function.Type("reader",wtkx.io.UrlcInputStream.class,(new Class[]{Component.class,java.net.URLConnection.class}));
        public final static wtkx.be.Function.Type writer = new wtkx.be.Function.Type("writer",wtkx.io.UrlcOutputStream.class,(new Class[]{Component.class,java.net.URLConnection.class}));
        public final static wtkx.be.Function.Type request = new wtkx.be.Function.Type("request",Void.class,(new Class[]{Component.class,wtkx.io.XMLHttpRequest.class}));
        public final static wtkx.be.Function.Type response = new wtkx.be.Function.Type("response",Void.class,(new Class[]{wtkx.io.XMLHttpRequest.class}));



        public Type(String name, Class returntype, Class[] parameters) {
            super(name,returntype,parameters);
        }

    }


    public Function(Component c, Type e, String t){
        super(e,t);
    }

}
